package com.zky.service;

import com.zky.entity.Hotel;
import com.zky.mapper.HotelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class HotelService {
    
    @Autowired
    private HotelMapper hotelMapper;
    
    public List<Hotel> getAllHotels() {
        return hotelMapper.selectAll();
    }
    
    public List<Hotel> searchHotels(String keyword) {
        if (keyword == null || keyword.trim().isEmpty()) {
            return hotelMapper.selectAll();
        }
        return hotelMapper.searchByName(keyword.trim());
    }
    
    public Hotel getHotelById(Integer id) {
        return hotelMapper.selectById(id);
    }
    
    public void createHotel(Hotel hotel) {
        hotelMapper.insert(hotel);
    }
    
    public void updateHotel(Hotel hotel) {
        Hotel existingHotel = hotelMapper.selectById(hotel.getId());
        if (existingHotel == null) {
            throw new RuntimeException("要更新的酒店不存在");
        }
        hotelMapper.update(hotel);
    }
    
    public void deleteHotel(Integer id) {
        Hotel existingHotel = hotelMapper.selectById(id);
        if (existingHotel == null) {
            throw new RuntimeException("要删除的酒店不存在");
        }
        hotelMapper.deleteById(id);
    }
} 